package com.lifa.controller;

import com.lifa.dao.FuwuXiangmuDao;
import com.lifa.entity.FuwuXiangmu;
import com.lifa.service.FuwuXiangmuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/fuwu")
@Scope("prototype")
public class FuwuXiangmuController {
    @Autowired
    private FuwuXiangmuService fuwuXiangmuService;
    @Autowired
    private FuwuXiangmuDao fuwuXiangmuDao;

    /**
     * 查询
     * @return
     */
    @RequestMapping("/query")
    @ResponseBody
    public List<FuwuXiangmu> query(){
        return fuwuXiangmuService.list();
    }


    /**
     * 根据id删除服务信息
     * @param fuwu_Id
     * @return
     */
    @RequestMapping("/shanchu")
    @ResponseBody
    public int shanchu(int fuwu_Id){
        return fuwuXiangmuService.delete(fuwu_Id);
    }

    /**
     * 添加服务信息
     * @returnw
     */
    @RequestMapping("/inst")
    @ResponseBody
    public int inst(FuwuXiangmu fuwuXiangmu){
        return fuwuXiangmuService.zj(fuwuXiangmu);
    }

    /**
     * 根据id修改服务信息
     * @return
     */
    @RequestMapping("/xg")
    @ResponseBody
    public int xg(FuwuXiangmu fuwuXiangmu){
        System.out.println(fuwuXiangmu.getFuwu_Id()+"---");
        return fuwuXiangmuService.update(fuwuXiangmu);
    }

    /**
     * 根据id查询
     * @param fuwu_Id
     * @return
     */
    @RequestMapping("/queryById")
    @ResponseBody
    public FuwuXiangmu queryById(int fuwu_Id){
        return fuwuXiangmuService.queryById(fuwu_Id);
    }

    /**
     * 分页
     * @param name
     * @param offset
     * @param limit
     * @return
     */
    @RequestMapping("/queryByName")
    @ResponseBody
    public Map<String,Object> queryPageByName(String name, int offset, int limit){
        Map<String,Object> map = new HashMap<>() ;
        map.put("rows",fuwuXiangmuDao.queryPage(name,offset,limit)) ;
        map.put("total",fuwuXiangmuDao.getTotalCount(name)) ;
        return  map ;
    }
}
